/*
 * ReportDaoImpl.java
 *
 * Created on January 26, 2009, 3:45 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package org.vacuela.publishmx.dal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.vacuela.publishmx.constant.Constants;
import org.vacuela.publishmx.domains.Message;
import org.vacuela.publishmx.domains.OutputMessage;
import org.vacuela.publishmx.domains.ReportCriteria;

/**
 *
 * @author nestor.carrasco
 */
public class ReportDaoImpl extends SqlMapClientDaoSupport implements ReportDaoIfc {

    /** Creates a new instance of ReportDaoImpl */
    public Map<String, List<Message>> getReportMessages(ReportCriteria criteria) {
        Map mapResult = new HashMap();
        SqlMapClientTemplate template = getSqlMapClientTemplate();
        Map mapParams = new HashMap();
        mapParams.put("msgType", criteria.getMsgType());
        mapParams.put("fromDate", criteria.getFromDate());
        mapParams.put("toDate", criteria.getToDate());
        List<Message> msgLst = null;
        if (Constants.OUT_MSG_TYPE.equals( criteria.getMsgType())) {
            msgLst = (List<Message>) template.queryForList("getMessagesOutDetailsAgenda", mapParams);
            mapResult.put("msgOutAgenda", msgLst);
            msgLst = (List<Message>) template.queryForList("getMessagesOutDetailsInd", mapParams);
            mapResult.put("msgOutInd", msgLst);
        }else{
            msgLst = (List<Message>) template.queryForList("getMessagesInDetails", mapParams);
            mapResult.put("msgIn", msgLst);
        }
        return mapResult;
    }
    
    public OutputMessage getPhoneNumbersFromAgenda(int msgId){
        SqlMapClientTemplate template = getSqlMapClientTemplate();
        
        OutputMessage outMsg = (OutputMessage)template.queryForObject("getOnlyMessagesDetails",msgId);
        List phonesNumbers = (List)template.queryForList("getOnlyPhoneNumbersAgenda",msgId);
        outMsg.setNumbersList(phonesNumbers);
        return outMsg;
    }
    
    public OutputMessage getPhoneNumbersFromInd(int msgId){
        SqlMapClientTemplate template = getSqlMapClientTemplate();
        
        OutputMessage outMsg = (OutputMessage)template.queryForObject("getOnlyMessagesDetails",msgId);
        List phonesNumbers = (List)template.queryForList("getOnlyPhoneNumbersInd",msgId);
        outMsg.setNumbersList(phonesNumbers);
        return outMsg;
    }
}
